﻿using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.Data.Common;
//using System.Windows.Forms;
using System.Data.SqlTypes;
using System.Configuration;

/// <summary>
/// Summary description for Class1
/// </summary>
/// 

namespace Sql
{
    public class DcSql
    {
        private SqlConnection baglantim;
        public bool durum = false;


        public string DBBaglan(string DatabaseName)
        {
            //string server = "(local)";
            //string database = DatabaseName;
            //string username = "sa";
            //string password = "data1";


            string connStr = string.Empty;

            if (DatabaseName == "MikroDB")
                connStr = ConfigurationManager.AppSettings["Mikro.ConnectionString"].ToString();
            else
                connStr = ConfigurationManager.AppSettings["Prim.ConnectionString"].ToString();

            //string connectionstr = "User ID =" + username + "; Initial Catalog =" + database + "; Password =" + password + "; Data Source =" + server + ";Persist Security Info=False;";
            baglantim = new SqlConnection(connStr);

            try
            {
                baglantim.Open();
                durum = true;
                return "";
            }
            catch (Exception ex)
            {
                durum = false;
                return ((System.Data.SqlClient.SqlException)(ex)).Message.ToString();
            }
        }


        public SqlConnection GetConn()
        {
            return baglantim;
        }

        private bool connect()
        {
            try
            {
                baglantim.Open();
                return (durum = true);
            }
            catch
            {
                return (durum = false);
            }
        }


    }
}